---
# Configuration for the nuancier webapp

- name: clean yum metadata
  command: yum clean all
  tags:
  - packages

- name: install needed packages
  yum: pkg={{ item }} state=installed
  with_items:
  - nuancier
  - python-psycopg2
  - python-openid-cla
  - python-openid-teams
  - python-memcached
  - libsemanage-python
  - python-alembic
  tags:
  - packages

- name: copy sundry nuancier configuration
  template: src={{ item.file }}
            dest="{{ item.location }}/{{ item.dest }}"
            owner=apache group=apache mode=0600
  with_items:
  - { file: nuancier_admin.cfg, location: /etc/nuancier, dest: nuancier.cfg }
  - { file: alembic.ini, location: /etc/nuancier, dest: alembic.ini }
  tags:
  - config
  notify:
  - restart apache

#- name: create pictures folder where we upload the pictures
#  action: file state=directory
#               path=/var/cache/nuancier/pictures
#               owner=apache group=apache mode=0600
#  tags:
#  - setup
#
#- name: create the cache folder where nuancier creates the thumbnails
#  action: file state=directory
#               path=/var/cache/nuancier/cache
#               owner=apache group=apache mode=0600
#  tags:
#  - setup

- name: create the database scheme
  command: /usr/bin/python2 /usr/share/nuancier/nuancier_createdb.py
  environment:
      NUANCIER_CONFIG: /etc/nuancier/nuancier.cfg

- name: replace the nuancier configuration file by the one with the normal user
  template: src={{ item.file }}
            dest="{{ item.location }}/{{ item.file }}"
            owner=apache group=apache mode=0600
  with_items:
  - { file: nuancier.cfg, location: /etc/nuancier }
  - { file: nuancier.conf, location: /etc/httpd/conf.d }
  - { file: nuancier.wsgi, location: /usr/share/nuancier }
  tags:
  - config
  notify:
  - restart apache

- name: set sebooleans so nuancier can talk to the db
  action: seboolean name=httpd_can_network_connect_db
                    state=true
                    persistent=true

- name: check semanage ports
  command: semanage port -l
  register: semanageoutput

- name: set ports so httpd can talk to fedmsg endpoints
  command: semanage port -a -t http_port_t -p tcp 3001-3100
  when: semanageoutput.stdout.find("3001-3100") == -1

- name: apply selinux type to static files
  file: >
    dest=/usr/lib/python2.6/site-packages/nuancier/static/
    setype=httpd_sys_content_t
    state=directory
    recurse=yes

- name: set sebooleans so apache can use glusterfs
  action: seboolean name=httpd_use_fusefs
                    state=true
                    persistent=true

- name: apply selinux type to the wsgi file
  file: >
    dest=/usr/share/nuancier/nuancier.wsgi
    setype=httpd_sys_content_t
